home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Netware Super Library
/
Netware Super Library.iso
/
note_tip
/
file_own
/
fileown.c
next >
Wrap
C/C++ Source or Header
|
1991-03-07
|
5KB
|
190 lines
/********************************
** **
** Fileown.c --by John Adkins **
** v1.00 **
**----------------------------**
** **
** Examines files in the cur- **
** rent directory and sets **
** the owner to the current **
** user if no owner is already**
** set. **
** **
**----------------------------**
** **
** Copyright (C) 1991 **
** Illinois Department **
** of Revenue **
** **
** All rights reserved. **
** **
**----------------------------**
** **
** Written in Turbo C++ v1.0 **
** and the Novell C API libs. **
** **
********************************/
/********************************
******* INCLUDES *************
********************************/
#include <stdio.h>
#include <string.h>
#include <dir.h>
#include <dos.h>
/********************************
******* NOVELL API ***********
********************************/
#include <nit.h>
#include <niterror.h>
/********************************
******* DEFINES **************
********************************/
#define ID_SIZE 48
#define FILENAME_SIZE 64
/********************************
******* TYPEDEFS *************
********************************/
/********************************
******* GLOBALS **************
********************************/
/********************************
******* PROTOTYPES ***********
********************************/
void main(int,char **);
void GetLoginName(char *,long *);
/********************************
******* ROUTINES *************
********************************/
void GetLoginName(loginname,objectID)
char *loginname;
long *objectID;
{
WORD connect,connectID;
WORD objtype;
char loggedin[7];
connect=GetConnectionNumber();
GetConnectionInformation(connect,loginname,&objtype,objectID,loggedin);
return;
}
void main(argc,argv)
int argc;
char *argv[];
{
int error;
int curdrv;
BYTE dh;
int seq;
char fname[FILENAME_SIZE+1];
char userid[ID_SIZE+1];
long userobj;
BYTE fattr,extfattr;
long fsize;
char fcreatedte[2];
char flastacc[2];
char flastupd[4];
char flastarc[4];
long fownerid;
char owner[ID_SIZE];
WORD ownertype;
char fpath[FILENAME_SIZE+1];
struct ffblk ffblk;
puts("\nFileOwn v1.00\nCopyright (C) 1991, Illinois Department of Revenue");
puts("All rights reserved.\n");
error=0;
GetLoginName(userid,&userobj);
curdrv=getdisk();
dh=GetDirectoryHandle(curdrv);
if(dh)
{
if(getcwd(fpath,FILENAME_SIZE))
{
printf("\nScanning directory %s:\n\n",fpath);
error=findfirst("*.*",&ffblk,0);
while(!error)
{
seq=-1; /* -1 is a magic number which means "find first" */
fownerid=0L; /* this line is just a precaution */
error=ScanFileInformation(dh,ffblk.ff_name,0x00,&seq,fname,&fattr,
&extfattr,&fsize,fcreatedte,flastacc,flastupd,
flastarc,&fownerid);
if(error)
{
fprintf(stderr,"Error scanning file info for %s.\n",ffblk.ff_name);
continue;
}
error=GetBinderyObjectName(fownerid,owner,&ownertype);
if(error)
{
if(error==NO_SUCH_OBJECT)
{
printf("%s owner id=0x%LX not found",ffblk.ff_name,fownerid);
if(argc==1)
{
printf(", setting %s as new owner.\n",userid);
error=SetFileInformation(dh,ffblk.ff_name,0x00,fattr,
extfattr,fcreatedte,flastacc,flastupd,
flastarc,userobj);
if(error!=SUCCESSFUL)
{
fprintf(stderr,"Unexpected error (0x%X) setting file info.\n",error);
fprintf(stderr,"File=%s, new owner=%s (0x%LX)\n",ffblk.ff_name,userid,userobj);
continue;
}
}
else
{
printf(", no changes made.\n");
}
}
else
{
error=20;
continue;
}
}
else
{
printf("%s owned by %s.\n",fname,owner);
}
error=findnext(&ffblk);
}
}
else
{
fprintf(stderr,"Unable to get dir path for drive #%d\n",curdrv);
}
}
else
{
error=20;
fprintf(stderr,"Unable to get dir handle for drive #%d\n",curdrv);
}
exit(error);
}